package net.oschina.app.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.MApp;
import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Comment;
import net.oschina.app.ui.view.CircleImageView;
import net.oschina.app.ui.widget.TweetTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by CXB on 2017/4/7.
 */

public class TweetDetailAdapter extends BaseRecyclerViewAdapter {
    private List<Comment> commentlist;

    public TweetDetailAdapter(Context context, List<Comment> commentlist) {
        super(context);
        this.commentlist = commentlist;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.from(parent.getContext()).inflate(R.layout.tweetdetail_item, parent, false);
        MyHold myHold = new MyHold(view);
        return myHold;
    }

    @Override
    public int getItemCount() {
        return commentlist.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        MyHold hold = (MyHold) holder;
        Glide.with(MApp.mContext).load(commentlist.get(position).getPortrait()).into(hold.mIvTweetFace);
        hold.mTvTweetName.setText(commentlist.get(position).getAuthor());
        hold.mTvTweetTime.setText(commentlist.get(position).getPubDate());
        hold.mTweetItem.setText(commentlist.get(position).getContent());
    }

    class MyHold extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_tweet_face)
        CircleImageView mIvTweetFace;
        @BindView(R.id.tv_tweet_name)
        TextView mTvTweetName;
        @BindView(R.id.tweet_item)
        TweetTextView mTweetItem;
        @BindView(R.id.iv_tweet_image)
        ImageView mIvTweetImage;
        @BindView(R.id.tv_tweet_time)
        TextView mTvTweetTime;

        public MyHold(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
